import Feature from 'ol/Feature'
import Point from 'ol/geom/Point'
import { isArray } from '../utils/index'
import { v4 as uuidv4 } from 'uuid'
/**
 * 绘制点
 */
export function point (pointList, type = 'icon') {
  if (!isArray(pointList) || !pointList.length) {
    throw Error('绘制点标注：参数格式错误')
  }
  const ids = []
  const features = pointList.map(item => {
    const {
      name,
      img: imgType,
      drag = false,
      textColor,
      longitude,
      latitude,
      id = uuidv4(),
    } = item || {}
    const lnglat = [parseFloat(longitude), parseFloat(latitude)]
    ids.push(id)
    return new Feature({
      type,
      name,
      imgType,
      id,
      drag,
      textColor,
      property: { ...item },
      geometry: new Point(lnglat)
    })
  })
  return {
    features,
    ids
  }
}